<?php
function getContentPages($site=0)
{
	$where = '';
	if($site > 0)
	{ $where = ' WHERE site_id='.$site; }
	$i=0;
	$result = mysql_query('SELECT id, name_l, name_r FROM '.DB_PERFIX.'template_html '.$where.' ORDER BY name_l;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['name_l'] = $row['name_l'];
		$item[$i]['name_r'] = $row['name_r'];	
		$i++;
	}
	return $item;
}

function getSiteList()
{
	$i=0;
	$select = 'id, title';
	$result = mysql_query('SELECT '.$select.' FROM '.DB_PERFIX.'sites ORDER BY title;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['title'] = $row['title'];
		$i++;
	}
	return $item;
}

function getFeaturedLocations()
{
	$i=0;
	$result = mysql_query('SELECT id, title FROM '.DB_PERFIX.'featured_locations;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['title'] = $row['title'];
		$i++;
	}
	return $item;
}

function getItemFeaturedLocations($type, $id)
{
	if(($type > 0) && ($id > 0))
	{
		$result = mysql_query('SELECT id, location FROM '.DB_PERFIX.'featured WHERE type='.$type.' AND featured_id='.$id.';');
		$i=0;
		while($row = mysql_fetch_array($result))
		{
			$item[$i]['id'] = $row['id'];
			$item[$i]['location'] = $row['location'];
			$i++;
		}
		return $item;
	}
}

function deleteFromFeatured($id, $location)
{
	$result = mysql_query('DELETE FROM '.DB_PERFIX.'featured WHERE featured_id='.$id.' AND location='.$location.' LIMIT 1;');
	return $result;
}

function setAsFeatured($location, $type, $id)
{
	$insert = 'INSERT INTO '.DB_PERFIX.'featured (`location`, `type`, `featured_id`) VALUES ('.$location.', '.$type.', '.$id.');';
	$result = mysql_query($insert);
	return $result;
}

function getWord($value, $words)
{
	if($words[$value])
	{ return $words[$value]; }
	else
	{
		$result = mysql_query('SELECT '.LANG.' FROM '.DB_PERFIX.'words WHERE value="'.$value.'";');
		while($row = mysql_fetch_array($result))
		{ $words[$row['value']] = $row[LANG]; }
		return $words[$value];
	}
}
?>